{% extends "base.html" %}

{% block title %}我的订单 - 农场{% endblock %}

{% block content %}
    <h1 class="text-3xl font-bold mb-6">我的订单</h1>
    
    {% if not orders %}
        <div class="bg-white rounded-lg shadow-md p-8 text-center">
            <i class="fa fa-file-text-o text-6xl text-gray-300 mb-4"></i>
            <h2 class="text-xl font-semibold mb-2">暂无订单</h2>
            <p class="text-gray-600 mb-6">快去购物吧！</p>
            <a href="{{ url_for('index') }}" class="btn-primary">
                浏览商品
            </a>
        </div>
    {% else %}
        <div class="bg-white rounded-lg shadow-md overflow-hidden">
            <table class="min-w-full divide-y divide-gray-200">
                <thead class="bg-gray-50">
                    <tr>
                        <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">订单编号</th>
                        <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">日期</th>
                        <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">金额</th>
                        <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">状态</th>
                        <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">操作</th>
                    </tr>
                </thead>
                <tbody class="bg-white divide-y divide-gray-200">
                    {% for order in orders %}
                        <tr>
                            <td class="px-6 py-4 whitespace-nowrap">
                                <div class="text-sm font-medium text-gray-900">{{ order['id'] }}</div>
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap">
                                <div class="text-sm text-gray-900">{{ order['order_date'] }}</div>
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap">
                                <div class="text-sm text-gray-900">¥{{ "%.2f"|format(order['total_amount']) }}</div>
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap">
                                {% if order['status'] == 'pending' %}
                                    <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-yellow-100 text-yellow-800">
                                        待支付
                                    </span>
                                {% elif order['status'] == 'shipped' %}
                                    <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-blue-100 text-blue-800">
                                        已发货
                                    </span>
                                {% elif order['status'] == 'delivered' %}
                                    <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">
                                        已送达
                                    </span>
                                {% elif order['status'] == 'cancelled' %}
                                    <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-red-100 text-red-800">
                                        已取消
                                    </span>
                                {% endif %}
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
                                <a href="{{ url_for('order_detail', order_id=order['id']) }}" class="text-blue-600 hover:text-blue-900">
                                    查看详情
                                </a>
                            </td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    {% endif %}
{% endblock %}
